import React from 'react';
import {messages} from "share/common";
import moment from "moment/moment";
import {Radio, Button, Icon} from 'antd'
import CarUseSystem from "./car-use-system";

export default {
  newOpenConsumerSearchForm(type){
    switch (type){
      case 'didi':
      case 'ctrip':
      case 'heliosHotel':
      case 'zhenxuanair':
      case 'meiya':
      case 'travelnoone':
        return [
          {
            id: 'levelCode',
            label: messages('supplier-1.key36')/*层级*/,
            component: <Radio.Group>
              <Radio value="ALL">{messages('common.all')/*全部*/}</Radio>
              <Radio value="COMPANY">{messages('supplier-1.key37')/*公司*/}</Radio>
              <Radio value="TENANT">{messages('supplier-1.key38')/*租户*/}</Radio>
            </Radio.Group>,
            initialValue: 'ALL',
            dataIndex: 'levelCode',
            parser: value => ({
              levelCode: value !== 'ALL' ? value : null
            }),
            tagParser: value => {
              if (value === 'ALL') {
                return messages('common.all')/*全部*/;
              } else {
                return value === "COMPANY" ? messages('supplier-1.key37')/*公司*/ : messages('supplier-1.key98')/*帐套*/;
              }
            }
          },
          {
            component: 'Chooser',
            id: 'distLevelOrgName',
            dataIndex: 'distLevelOrgName',
            label: messages('supplier-1.key99')/*启用公司*/,
            props: {
              type: 'permission_company',
              valueKey: type === 'ctrip' || type === 'travelnoone' ? 'id' : 'companyOID',
              labelKey: 'name',
              single: false,
              onlyNeed: type === 'ctrip' || type === 'travelnoone' ? 'id' : 'companyOID',
            },
            parser: value => ({
              distLevelOrgIds: value && value.length > 0 ? value : [],
            }),
          },
        ];
      default: return [
        {
          type: 'input',
          id: 'companyCode',
          dataIndex: 'companyCode',
          label: messages('supplier-1.key102')/*公司代码/名称*/ ,
          props: {
            placeholder: messages('supplier-1.key103')/*请输入temp2*/,
          },
          parser: value => ({
            key: value,
          }),
        },
      ]
    }
  },

  getOtherDepSetting(context, type) {
    let isEdit = context.state.isDepEdit;
    let depData = context.state.depData;
    let tempDepConfig = context.state.tempDepConfig;
    let syncDepData = context.state.syncDepData;
    let onEdit = () => context.setState({isDepEdit: true});
    let onChange= e => context.setState({tempDepConfig: e.target.value});
    let onCancel = () => context.setState({isDepEdit: false});
    return (
      <div className='consumer-other-setting-card-container'>
        <h3>{messages('supplier-1.key104')/*部门同步*/}</h3>
        <ul>
          <li key='data'>
            {messages('supplier-1.key105')/*部门数据*/}：
            {isEdit ? (
              <span>
                <Radio.Group value={tempDepConfig} onChange={onChange}>
                  <Radio value={'false'}>{messages('supplier-1.key106')/*不同步*/}</Radio>
                  <Radio value={'true'}>{messages('supplier-1.key107')/*同步*/}</Radio>
                </Radio.Group>
                &nbsp;&nbsp;
                <Button type="primary" size='small' onClick={() => context.saveDepSynConfig(tempDepConfig)}>{messages('common.save')/*保存*/}</Button>
                <Button size='small' onClick={onCancel} style={{marginLeft: 10}}>{messages('common.cancel')/*取消*/}</Button>
              </span>
            ) : (
              <span>
                {depData === 'true' ? messages('supplier-1.key107')/*同步*/ : messages('supplier-1.key106')/*不同步*/}
                <Icon
                  type="edit"
                  className='default-color-font'
                  style={{cursor: 'pointer', marginLeft: 6}}
                  onClick={onEdit}
                />
              </span>
            )}
          </li>
          {
            !!(depData === 'true') && (
              <li key='async'> {messages('supplier-1.key67')/*点击*/}&nbsp;
                <a onClick={context.onSyncDepData}>{messages('supplier-1.key108')/*同步部门数据*/}</a>
                &nbsp;{messages('supplier-1.key109')/*可手工同步部门增量，同步需要时间，可先处理其他事物，之后回到该页面刷新结果*/}
              </li>
            )
          }
          {
            !!(depData === 'true') && (
              <li key='refresh'> {messages('supplier-1.key67')/*点击*/}&nbsp;
                <a onClick={context.updateSyncDepData}>{messages('supplier-1.key70')/*刷新*/}</a>
                &nbsp;{messages('supplier-1.key71')/*可获取最近一次同步结果*/}：
                {
                  syncDepData.batch ? (
                    <span>
                      <sapn style={{ color: '#000' }}>
                        {moment(new Date(parseInt(syncDepData.batch))).format('YYYY-MM-DD HH:mm')}
                        {`共同步完成${syncDepData.errorTotal + syncDepData.successTotal}个，其中成功${syncDepData.successTotal}个`}
                        ， {messages('supplier-1.key73')/*失败*/}
                        {context.failText(syncDepData)} {messages('supplier-1.key110')/*个*/}
                      </sapn>
                      {messages('supplier-1.key67')/*点击*/}&nbsp;
                      <a onClick={context.downloadFailSyncDepData}>
                        {messages('supplier-1.key111')/*下载同步失败部门信息*/}
                      </a>
                    </span>
                  ) : messages('supplier-1.key76')/*暂无同步结果*/
                }
              </li>
            )
          }
        </ul>
      </div>
    )
  },

  getDidiSetting(context, type) {
    return (
      <div>
      <div className='consumer-other-setting-card-container'>
        <h3>{messages('supplier-1.key112')/*滴滴设置*/}</h3>
        <ul>
          <li key='invoice'>
            <span dangerouslySetInnerHTML={{__html: messages('supplier-1.key113')/*维护开票的抬头信息，点击<a onclick=\"window.open('https://es.xiaojukeji.com/platform/invoice/title', '_blank')\">新增开票资质</a>*/}}/>
          </li>
          <li key='other'>
            <span dangerouslySetInnerHTML={{__html: messages('supplier-1.key114')/*其他滴滴设置请前往<a onclick=\"window.open('https://es.didichuxing.com/', '_blank')\">滴滴企业平台</a>进行配置*/}}/>
          </li>
        </ul>
      </div>
      {/* 滴滴用车制度导入 */}
       <CarUseSystem/>
       </div>
    )
  },
}
